package com.yixun.qfbao.hander;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yixun.qfbao.apidto.UpdateAccountTypeReqDto;
import com.yixun.qfbao.apidto.UpdateAccountTypeResDto;
import com.yixun.qfbao.dto.base.BaseRequestDTO;
import com.yixun.qfbao.dto.base.BaseResponseDTO;
import com.yixun.qfbao.hander.base.CommonAbstractHander;
import com.yixun.qfbao.model.PartnerInfo;
import com.yixun.qfbao.model.dto.PartnerInfoDto;
import com.yixun.qfbao.service.PartnerInfoService;
import com.yixun.qfbao.utils.LoginUtils;
import com.yixun.qfbao.xf.model.enums.ResultEnum;

/**
 * @author zilong.liu
 * @date 2020-11-28
 *
 * desc:
 *     
 */
@Service("updateAccountTypeHander")
public class UpdateAccountTypeHander extends CommonAbstractHander {

	@Autowired
    private LoginUtils loginUtils;
	
	@Autowired
	private PartnerInfoService partnerInfoService;
	
	@Override
	public BaseResponseDTO doBusiness(BaseRequestDTO reqDto) {
		UpdateAccountTypeReqDto updateAccountTypeReqDto = (UpdateAccountTypeReqDto) reqDto.getParams();
		BaseResponseDTO<UpdateAccountTypeResDto> res = new BaseResponseDTO<>();
		PartnerInfo pi = loginUtils.getUser(updateAccountTypeReqDto.getUserId());
        if (pi == null) {
            res.setResult(ResultEnum.FAIL.getNo());
            res.setErrorMsg("未登录");
            return res;
        }
        PartnerInfoDto partnerInfoDto = new PartnerInfoDto();
        partnerInfoDto.setId(updateAccountTypeReqDto.getId());
        partnerInfoDto.setAccountType(updateAccountTypeReqDto.getAccountType());
        String result = partnerInfoService.setAgencyAccountType(partnerInfoDto);
        if("succ".equals(result)) {
        	res.setResult(ResultEnum.SUCCESS.getNo());
        	return res;
        }
        res.setResult(ResultEnum.FAIL.getNo());
        res.setErrorMsg(result);
		return res;
	}

}
